﻿using System;
using RpcHelper;
using RpcModel;
using Wedonek.RpcStore.Service.DAL;
using Wedonek.RpcStore.Service.Interface;
using Wedonek.RpcStore.Service.Model;

namespace Wedonek.RpcStore.Service.Collect
{
    internal class SysConfigCollect : BasicCollect<SysConfigDAL>, ISysConfigCollect
    {
        public SysConfigDatum[] Query(QuerySysParam query, IBasicPage paging, out long count)
        {
            return this.BasicDAL.Query(query, paging, out count);
        }

        private void _CheckIsExists(SysConfigAddParam config)
        {
            if (this.BasicDAL.CheckIsExists(config))
            {
                throw new ErrorException("rpc.sys.config.repeat");
            }
        }

        public SysConfigDatum Get(long id)
        {
            return this.BasicDAL.Get(id);
        }
        public void SetIsEnable(long id, bool isEnable)
        {
            this.BasicDAL.SetIsEnable(id, isEnable);
        }
        public long Add(SysConfigAddParam add)
        {
            this._CheckIsExists(add);
            return this.BasicDAL.Add(add);
        }
        public void Set(long id, SysConfigSetParam config)
        {
            config.ToUpdateTime = DateTime.Now;
            this.BasicDAL.Set(id, config);
        }

        public void Drop(long id)
        {
            this.BasicDAL.Drop(id);
        }

        public SysConfigDatum Find(string systemType, string key)
        {
            SysConfigDatum config = this.BasicDAL.FindConfig(systemType, key);
            if (config == null)
            {
                throw new ErrorException("rpc.sys.config.find.not.find");
            }
            return config;
        }
    }
}
